library Wave2 initializer init requires LegacySystem, LegacyPlayerInterface, LoadCommand


    private function AutomatedCombatAssistance takes nothing returns nothing
        local integer i = 20
        local integer i2 = 0
        local integer id
        local real x = GetUnitX(udg_BlackHawk)
        local real y = GetUnitY(udg_BlackHawk)
        local player p
        call IssuePointOrder(udg_GlobalUnit[20],"move",x,y)
        call IssuePointOrder(udg_GlobalUnit[21],"move",x,y)
        call PolledWait(6.)
        call RemoveUnit(udg_GlobalUnit[20])
        call RemoveUnit(udg_GlobalUnit[21])
        call RemoveUnit(udg_BlackHawk)
        call RemoveRect(gg_rct_SelectionZone)
        
        // disable player selection here
        //call DestroyTrigger(gg_trg_Player_Selection)
        
        set i = 1
        set udg_Mode = 1
		call SetLoadCommandEnabled(false)
        loop
            exitwhen i > udg_InitialPlayers
            set id = udg_Sorted[i]
            set p = ConvertedPlayer(id)
			
            call FogModifierStop(udg_SelectionView[id])
            call DestroyFogModifier(udg_SelectionView[id])

            if udg_HeroSelected[id]==false and GetPlayerSlotState(p)!=PLAYER_SLOT_STATE_LEFT then
                call CreateUnit(p,'Hpal',0.0,0.0,0)
            endif
            set i = i + 1
        endloop
        
        /*
        // looks like just secret check for cheating...
        set i=1 //Hero Ammunition Audit
        loop
            exitwhen i>udg_Players
            if GetWidgetLife(udg_Hero[udg_Sorted[i]])>0.405 and GetUnitUserData(udg_Hero[udg_Sorted[i]])<1 then
                call SetUnitUserData(udg_Hero[udg_Sorted[i]],50)
                set udg_Rounds[udg_Sorted[i]] = 50
                set udg_Reloading[udg_Sorted[i]] = 0
            endif
            set i=i+1
        endloop
        */
        
        if i2==1 then
            //call EnableTrigger(gg_trg_Dynamic_Evasion)
            //call ALICE2Text(6.0, "|cffcd950cALICE|r : Automated Combat Assistance enabled for Privates. Input -aca to deactivate.")
        endif
       
        call SquadRatingCalc.execute()
        call PolledWait(3.)

        if udg_SquadXP>50000 then
            set udg_DMKillingSpree[99] = 8 //Immortal Revive Rate
            set udg_CloudFactor=(udg_CloudFactor*3)/5
            set i=0
            loop
                exitwhen i>10
                set udg_AilmentChance[((i*7)+2)]=4
                set i=i+1
            endloop
            set i=0
            loop
                exitwhen i>10
                set udg_AilmentChance[((i*7)+3)]=5
                set i=i+1
            endloop
            set i=0
            loop
                exitwhen i>10
                set udg_AilmentChance[((i*7)+4)]=8
                set i =i+1
            endloop
            set i=0
            loop
                exitwhen i>10
                set udg_AilmentChance[((i*7)+5)]=8
                set i=i+1
            endloop
            set i=0
            loop
                exitwhen i>10
                set udg_AilmentChance[((i*7)+6)]=6
                set i=i+1
            endloop
            set i=0
            loop
                exitwhen i>10
                set udg_AilmentChance[((i*7)+7)]=18
                set i=i+1
            endloop
        else
            set udg_DMKillingSpree[99] = 6
        endif
        if udg_SquadXP<50000 then
            call SetPlayerHandicap(Player(13),GetPlayerHandicap(Player(13))-0.1)
            call SetPlayerHandicap(Player(14),GetPlayerHandicap(Player(14))-0.1)
        endif
        if udg_SquadXP>200000 and udg_Mode==1 then
           set udg_XPFactor = udg_XPFactor*2.5
        elseif udg_SquadXP>150000 and udg_Mode==1 then
           set udg_XPFactor = udg_XPFactor*2.25
        elseif udg_SquadXP>100000 and udg_Mode==1 then
           set udg_XPFactor = udg_XPFactor*2.
        elseif udg_SquadXP>50000 and udg_Mode==1 then
           set udg_XPFactor = udg_XPFactor*1.5
        endif
        set udg_Mode = 1
    endfunction


    private function Wave2a takes nothing returns nothing
        local integer i = 1
        set udg_CurrentWave = 2
        set udg_Visibility = 77
        call IntermissionRestore()
        set udg_Visibility = 76
        call IntermissionRestore()
        call GenericActions.execute()
        if GetRandomInt(1,4)==1 then
            call SpawnRectRandom(gg_rct_SpawnSouthWaterfall,Player(14),'nsw1',udg_Spawn)
            call PolledWait(5.)
            call SpawnRectRandom(gg_rct_SpawnEastCave,Player(13),'nsw1',udg_Spawn)
            call PolledWait(5.)
            call SpawnRectRandom(gg_rct_SpawnNorthWaterfall,Player(14),'nsw1',GetRandomInt(1,udg_Spawn))
        else
            call SpawnRectRandom(gg_rct_SpawnEastCave,Player(14),'u000',udg_Spawn)
            call SpawnRectRandom(gg_rct_SpawnNorthWaterfall,Player(14),'u000',udg_Spawn)
            call PolledWait(10.)
            call SpawnRectRandom(gg_rct_SpawnSouthWaterfall,Player(13),'u000',2+udg_Spawn)
            call SpawnRectRandom(gg_rct_SpawnTownWestCave,Player(14),'u000',2+udg_Spawn)
        endif
        call AutomatedCombatAssistance.execute()
        call RandomSpawn('nsw1',1,udg_Players)

        call SpawnShredder()

        call PolledWait(30.*udg_Pace)
        if udg_SquadXP>30000 and GetRandomInt(0,50)==1 then
            call RandomSpawn('n00X',2,1) //Evil Dog
        endif
        call GeneralText(5.0, "|cfff3ad00Marine|r : The supplies are scattered all over. We need to cover more ground." )
        call GankMarine(Player(13),'nzom',1+udg_Spawn,1800,3500)
        if udg_Players>=6 then
            call RandomSpawn('ugar',1,2)
            call RandomSpawn('n002',1,2)
        endif
        call FieldChat(udg_Ogilvy, 5.0, "|cfff3ad00Ogilvy|r : We don't have weapons, but we'll do what we can. I'm glad you're here." )
        call PolledWait(30.0*udg_Pace)
        set i=1
        loop
            exitwhen i>udg_Players
            if udg_Experience[udg_Sorted[i]]<500 then
                call DisplayTimedTextToPlayer(ConvertedPlayer(udg_Sorted[i]),0.0,0.0,10.0,"You will not revive after death. You may receive ailments from Zulus. Fibrin Bandages cure open wounds and Anti-Venoms cure most poisoning.")
            endif
            set i=i+1
        endloop
        set i=1
        set udg_soundpath = "Sound\\Time\\DuskWolf.wav"
        call PlaySoundPath.execute()
        if GetRandomInt(1,10)==1 and (getBoolean(null,"FOPresent") == true) then
            call GeneralText(3.0, "|cfff3ad00Forward Observer|r : Sending Iron Hand our Delta Tango." )
        endif
        if udg_HitsTaken<5 then
            call GankMarine(Player(13),'n004',2*udg_Spawn,1800,3500)
        else
            call GankMarine(Player(13),'nzom',1+udg_Spawn,1800,3500)
        endif
        if GetRandomInt(1,10)==1 then
            call GeneralText(3.0, "|cfff3ad00Marine|r : Maintain visual of all entry points! Zulus will rip us apart if they close in on us." )
        elseif GetRandomInt(1,7)==1 then
            call GeneralText(3.0, "|cffcd950cMarine|r : Watch out for Blinks. Nasty fuckers ripped Charlie Company in pieces." )
        endif
        call GankMarine(Player(14),'nzom',2+udg_Spawn,1800,3500)
        call PolledWait(30.0*udg_Pace)
        set i=1
        loop
            exitwhen i>udg_Players
            if udg_Experience[udg_Sorted[i]]<500 then
                call DisplayTimedTextToPlayer(ConvertedPlayer(udg_Sorted[i]),0.0,0.0,10.0,"Follow the more experienced members of your squad. Input -tl to read your fire team's location. Working as a cohesive unit greatly improves survivability.")
            endif
            set i=i+1
        endloop
        set i=1
        if udg_SquadXP>45000 then
            call RandomSpawn('e00Q',2,udg_Spawn) // Parasite Mound
        endif
        call ItemSpawnN('shas',4) //Ammunition Box
        call RandomSpawn('u00L',3,IMinBJ(5,udg_Spawn)) //Blink
        call FieldChat(udg_Ogilvy, 5.0, "|cfff3ad00Ogilvy|r : There's so many of them. Boston must look like hell!" )
        call GankMarine(Player(13),'nzom',2+udg_Spawn,1800,3500)
        if GetRandomInt(0,50)==1 then
            call GankMarine(Player(13),'n00W',2+udg_Spawn,1800,3500)
            call GankMarine(Player(13),'n00W',2+udg_Spawn,1800,3500)
        endif
        if udg_Mode==2 then
            call GeneralText(10.0, "|cfff3ad00Major Grimes|r : Ooo-rah! Things are starting to look interesting. You gain movement and attack speed bonuses with rank, and sacrifice some health. That means you shitbirds who don't learn shit aren't going to have an easier time." )
        endif
        if udg_Players>0 then
            if GetWidgetLife(udg_Ogilvy)>0.405 and GetRandomInt(0,30)==1 then
                call ExecuteRegisteredFunction("Wave3c")
                //call Wave3c.execute()
            elseif GetRandomInt(0,3)==1 then
                call ExecuteRegisteredFunction("Wave3b")
                //call Wave3b.execute()
            else
                call ExecuteRegisteredFunction("Wave3a")
                //call Wave3a.execute()
            endif
        endif
    endfunction

    private function init takes nothing returns nothing
        call RegisterFunction("Wave2a", function Wave2a)
    endfunction

endlibrary
